package com.banana.springcloud.controller;

import com.banana.springcloud.entity.CommonResult;
import com.banana.springcloud.entity.Payment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author layman
 * @description: TODO
 * @date 2021/1/15
 */
@RestController
@RequestMapping("/consul/consumer")
public class ConsulOrderController {

    private static final String PAYMENT_URL = "http://consul-provider-payment";

    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/payment/create")
    public CommonResult<Payment> create(Payment payment){
        return restTemplate.postForObject(PAYMENT_URL+"/payment/create",payment,CommonResult.class);
    }
    @GetMapping("/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,CommonResult.class);
    }
    @GetMapping("/payment/discovery")
    public Object getDiscoveryInfo(){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/discovery",Object.class);
    }
    @GetMapping("/payment/consulInfo")
    public String getConsulInfo(){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/consulInfo",String.class);
    }
}
